package com.xjie.mall.goods.controller;


import com.xjie.mall.common.Result;
import com.xjie.mall.goods.model.Category;
import com.xjie.mall.goods.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 商品类目 前端控制器
 * </p>
 *
 * @author xjie
 * @since 2025-10-16
 */
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 根据父id查询子类分类
     * @param pid
     * @return
     */
    @GetMapping(value = "/parent/{pid}")
    public Result<List<Category>> list(@PathVariable(value = "pid") Integer pid)
    {
        List<Category> categories = categoryService.queryByParentId(pid);
        return Result.success(categories);
    }
}
